﻿/*
 * CanonOscar 0.1
 * Written by (c) agehack a.k.a. GUnitSoldier
 * Released under GNU GPL (http://www.gnu.org/copyleft/gpl.html)
 * 
 * http://www.agehack.pro/oscar
 */
using System;
using System.IO;
namespace Agehack.Icq
{
    public static partial class CanonOscar
    {
        /// <summary>
        /// Describes a Snac based on TLVs
        /// </summary>
        public abstract class SnacPack
        {
            public bool IsRawDataInside = false;
            public byte RawDataFlapChannel = 0x01;
            public abstract Snac MakeSnac();
            public Flap MakeFlap()
            {
                Snac s = MakeSnac();
                if (!IsRawDataInside)
                {
                    return new Flap(C_OSCAR_FLAP_ID, 0x02, s.GetBytes());
                }
                else
                {
                    Flap f = new Flap(C_OSCAR_FLAP_ID, RawDataFlapChannel, s.Body);
                    string hx = Agehack.TrafficLogger.ToHex(f.GetBytes())
                        .ToLower().Replace("-", " ");
                    return f;
                }
            }
            public void Send(FlapConnection con, bool stream)
            {
                Flap f = MakeFlap();
                if (!stream)
                    con.Send(f);
                else con.StreamWrite(f);
            }
        }
    }
}
